package com.daocao.hua.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.daocao.hua.R;
import com.daocao.hua.activity.InviteGiftV2Activity;
import com.daocao.hua.adapter.base.ItemAdapter;
import com.daocao.hua.constant.Const;
import com.daocao.hua.event.OnHomeEventMsg;
import com.daocao.hua.model.MoneyLogModel;
import com.daocao.hua.model.SignTaskModel;
import com.daocao.hua.util.Spans;
import com.daocao.hua.util.Util;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/10/17 0017.
 */

public class MySignAdapter extends ItemAdapter<SignTaskModel.DataBean, MySignAdapter.MySignViewHolder> {
    private final int px30;
    private final int px26;

    private Context context;

    public MySignAdapter(Context context) {
        super(context);
        this.context = context;
        px30 = context.getResources().getDimensionPixelSize(R.dimen.x30);
        px26 = context.getResources().getDimensionPixelSize(R.dimen.x26);
    }

    @Override
    public MySignViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MySignViewHolder(inflate(R.layout.item_sign, parent));
    }

    @Override
    public void onBindViewHolder(MySignViewHolder holder, int position) {
        SignTaskModel.DataBean item = getItem(position);


        Spanned rightContent = Spans.with(context).font(item.title, px30, 0xff5B5F8E).p().font("积分+" + item.score, px26, 0xffFF7A31).build();
        holder.txtContent.setText(rightContent);
        if (item.finish == 1) {
            holder.txtStatus.setBackgroundResource(R.drawable.bg_item_sign_bottom_unfinish);
            holder.txtStatus.setText("已完成");
        } else {
            holder.txtStatus.setBackgroundResource(R.drawable.bg_item_sign_bottom_finish);
            holder.txtStatus.setText("去完成");
        }
        switch (item.id) {
            case 1:
                holder.imgIcon.setImageResource(R.mipmap.img_sign_task1);
                break;
            case 2:
                holder.imgIcon.setImageResource(R.mipmap.img_sign_task2);
                break;
            case 3:
                holder.imgIcon.setImageResource(R.mipmap.img_sign_task3);
                break;
            case 4:
                holder.imgIcon.setImageResource(R.mipmap.img_sign_task4);
                break;
            case 5:
                holder.imgIcon.setImageResource(R.mipmap.img_sign_task5);
                break;
        }
        holder.txtStatus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (OnIdentityClick != null) {
                    OnIdentityClick.onClick(item.id);
                }

            }
        });
    }

    public interface OnIdentityClick {
        void onClick(int id);
    }

    private OnIdentityClick OnIdentityClick;

    public void setonIdentityListener(OnIdentityClick OnIdentityClick) {
        this.OnIdentityClick = OnIdentityClick;
    }

    static class MySignViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_icon)
        ImageView imgIcon;
        @BindView(R.id.txt_content)
        TextView txtContent;
        @BindView(R.id.txt_status)
        TextView txtStatus;

        public MySignViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
